package com.xiaoshuidi.cloud.module.iot.controller.admin;

import cn.hutool.json.JSONUtil;
import com.xiaoshuidi.cloud.module.iot.api.device.vo.AmmeterInfoResModel;
import com.xiaoshuidi.cloud.module.iot.api.device.vo.WaterMeterCommonResponseModel;
import com.xiaoshuidi.cloud.module.iot.controller.admin.doorlock.vo.OperateThirdDeviceRequestModel;
import com.xiaoshuidi.cloud.module.iot.controller.admin.doorlock.vo.OperateThirdDeviceResponseModel;
import com.xiaoshuidi.cloud.module.iot.controller.admin.doorlock.vo.PullThirdDeviceRequestModel;
import com.xiaoshuidi.cloud.module.iot.dal.model.AccessTokenRequestModel;
import com.xiaoshuidi.cloud.module.iot.dal.model.AccessTokenResponseModel;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.TbAccountDo;
import com.xiaoshuidi.cloud.module.iot.dal.pojo.TbDeviceDo;
import com.xiaoshuidi.cloud.module.iot.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.iot.service.impl.thirdPartImpl.EmecoInstanceServiceImpl;
import com.xiaoshuidi.cloud.module.iot.service.impl.thirdPartImpl.HangZhouXiZiInstanceServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：baohanzhong
 * @date ：Created 2024/8/22 20:08
 * @description：
 */
@RestController
@RequestMapping(ApiConstants.NAME+"/test/hzxz")
@Slf4j
public class TestHZXZController {

    @Autowired
    private HangZhouXiZiInstanceServiceImpl hangZhouXiZiInstanceService;


    @GetMapping("testGetAccessToken")
    public void testGetAccessToken() throws Exception {
        AccessTokenRequestModel accessTokenRequestModel = new AccessTokenRequestModel();
        accessTokenRequestModel.setAppId("HZPB");
        accessTokenRequestModel.setAppKey("c4ca4238a0b923820dcc509a6f75849b");
        AccessTokenResponseModel accessToken = hangZhouXiZiInstanceService.getAccessToken(accessTokenRequestModel);
        System.out.println(JSONUtil.toJsonStr(accessToken));
        log.info("testGetAccessToken=>result:{}", JSONUtil.toJsonStr(accessToken));

    }

    @GetMapping("testGetDevice")
    public void testGetDevice() throws Exception {
        PullThirdDeviceRequestModel pullThirdDeviceRequestModel = new PullThirdDeviceRequestModel();
        pullThirdDeviceRequestModel.setAccessToken("HZPB|c4ca4238a0b923820dcc509a6f75849b");
        TbAccountDo tbAccountDo = new TbAccountDo();
        tbAccountDo.setApiNo("hzxz_test");
        pullThirdDeviceRequestModel.setTbAccountDo(tbAccountDo);
        List<TbDeviceDo> device = hangZhouXiZiInstanceService.getDevice(pullThirdDeviceRequestModel);
        System.out.println(JSONUtil.toJsonStr(device));
        log.info("testGetDevice=>result:{}", JSONUtil.toJsonStr(device));
    }

    @GetMapping("testRefreshAmmeterInfo")
    public void testRefreshAmmeterInfo() throws Exception {
        TbDeviceDo tbDeviceDo = new TbDeviceDo();
        OperateThirdDeviceRequestModel operateThirdDeviceRequestModel = new OperateThirdDeviceRequestModel();
        operateThirdDeviceRequestModel.setAccessToken("");
        AmmeterInfoResModel ammeterInfoResModel = hangZhouXiZiInstanceService.refreshAmmeterInfo(tbDeviceDo, operateThirdDeviceRequestModel);
        System.out.println(JSONUtil.toJsonStr(ammeterInfoResModel));
        log.info("testrefreshAmmeterInfo=>result:{}", JSONUtil.toJsonStr(ammeterInfoResModel));
    }

    @GetMapping("testSwitchAmmeterOn")
    public void testSwitchAmmeterOn() throws Exception {
        OperateThirdDeviceRequestModel operateThirdDeviceRequestModel = new OperateThirdDeviceRequestModel();
        OperateThirdDeviceResponseModel operateThirdDeviceResponseModel = hangZhouXiZiInstanceService.switchAmmeterOn(operateThirdDeviceRequestModel);
        System.out.println(JSONUtil.toJsonStr(operateThirdDeviceResponseModel));
        log.info("testSwitchAmmeterOn=>result:{}", JSONUtil.toJsonStr(operateThirdDeviceResponseModel));
    }

    @GetMapping("testSwitchAmmeterOff")
    public void testSwitchAmmeterOff() throws Exception {
        OperateThirdDeviceRequestModel operateThirdDeviceRequestModel = new OperateThirdDeviceRequestModel();
        OperateThirdDeviceResponseModel operateThirdDeviceResponseModel = hangZhouXiZiInstanceService.switchAmmeterOff(operateThirdDeviceRequestModel);
        System.out.println(JSONUtil.toJsonStr(operateThirdDeviceResponseModel));
        log.info("testSwitchAmmeterOff=>result:{}", JSONUtil.toJsonStr(operateThirdDeviceResponseModel));
    }

}
